From 607127a5f432df017a93a6d847fd6b34bfbc7961 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 17 Jul 2006 21:10:16 +0000 Subject: [PATCH] Allow quoted commas in waypoint description when reading Magproto files. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@2240 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/magproto.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 03bea8c1e..c74ca60b3 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -536,7 +536,8 @@ static int terminit(const char *portname, int create_ok) { } } -static char *termread(char *ibuf, int size) { +static char *termread(char *ibuf, int size) +{ if (is_file) { return fgets(ibuf, size, magfile_h); } else { @@ -548,6 +549,38 @@ static char *termread(char *ibuf, int size) { } } +/* Though not documented in the protocol spec, if the unit itself + * wants to create a field containing a comma, it will encode it + * as 2C. We extrapolate that any 2 digit hex encoding may + * be valid. We don't do this in termread() since we need to do it + * after the scanf. This means we have to do it field-by-field + * basis. + * + * The buffer is modified in place and shortened by copying the remaining + * string including the terminator. + */ +static +void +mag_dequote(char *ibuf) +{ + char *esc = NULL; + + while ((esc = strchr (ibuf, 0x1b))) { + int nremains = strlen(esc); + if (nremains >= 3) { + static const char hex[16] = "0123456789ABCDEF"; + char *c1 = strchr(hex, esc[1]); + char *c2 = strchr(hex, esc[2]); + if (c1 && c2) { + int escv = (c1 - hex) * 16 + (c2 - hex); + *esc++ = escv; + /* buffers overlap */ + memmove(esc, esc+2, nremains - 2); + } + } + } +} + static void termwrite(char *obuf, int size) { if (is_file) { size_t nw; @@ -1025,6 +1058,8 @@ mag_wptparse(char *trkmsg) &alt,&altunits,shortname,descr); icone = strrchr(trkmsg, '*'); icons = strrchr(trkmsg, ',')+1; + + mag_dequote(descr); for (blah = icons ; blah < icone; blah++) icon_token[i++] = *blah; -- 2.30.2